package com.easylinkin.linkappapi.reportCenter.entity.vo;

import com.easylinkin.linkappapi.reportCenter.entity.ReportMachinery;
import lombok.Data;

/**
 * <p>
 * 设备运行报告塔吊/升降机统计
 * </p>
 *
 * @author kanyuanfeng
 * @since 2023-07-14
 */
@Data
public class ReportMachineryVo extends ReportMachinery {

    /**
     * 上月工作时长
     */
    private Double lastHour;

    /**
     * 上月告警次数
     */
    private Integer lastAlarmNum;

    /**
     * 时长环比
     */
    private String ratioHour;

    /**
     * 时长环比
     */
    private String ratioAlarm;

    /**
     * 工种时长环比
     * @return
     */
    public void computeRatioHour(){
        Double curHours = this.getHours();
        if (null != curHours && null != lastHour){
            if (curHours == 0) {
                if (lastHour==0){
                    this.ratioHour = "0%";
                }else {
                    this.ratioHour = String.format("%.2f", ((curHours.doubleValue()) / 1d * 100))+"%";
                }
            } else {
                this.ratioHour = String.format("%.2f", ((curHours - lastHour) / lastHour * 100))+"%";
            }
        }
    }

    /**
     * 告警次数环比
     * @return
     */
    public void computeRatioAlarm(){
        Integer lastAlarmNum = this.getLastAlarmNum();
        Integer curAlarmNum = getAlarmNum();
        if (null != getAlarmNum() && null != lastAlarmNum){
            if (lastAlarmNum== 0) {
                if (curAlarmNum==0){
                    this.ratioAlarm = "0%";
                }else {
                    this.ratioAlarm = String.format("%.2f", ((curAlarmNum.doubleValue()) / 1d * 100))+"%";
                }
            } else {
                this.ratioAlarm = String.format("%.2f", ((curAlarmNum.doubleValue() - lastAlarmNum.doubleValue()) / lastAlarmNum.doubleValue() * 100))+"%";
            }
        }
    }
}
